package com.aidex.biz.controller;

import java.util.List;
import com.aidex.common.annotation.Log;
import com.aidex.common.core.domain.R;
import com.github.pagehelper.PageInfo;
import com.aidex.common.core.page.PageDomain;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.aidex.common.enums.BusinessType;
import com.aidex.common.utils.poi.ExcelUtil;
import javax.validation.constraints.*;
import org.springframework.web.bind.annotation.*;
import com.aidex.common.core.controller.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import com.aidex.biz.domain.DaibanIng;
import com.aidex.biz.service.DaibanIngService;
import com.aidex.common.utils.SecurityUtils;

/**
 * 待办事项Controller
 * @author sean
 * @email 2074844820@qq.com
 * @date 2025-04-17
 */
@RestController
@RequestMapping("/biz/bizDaibanIng")
public class DaibanIngController extends BaseController
{
    @Autowired
    private DaibanIngService daibanIngService;

    /**
     * 查询待办事项列表
     */
    @PreAuthorize("@ss.hasPermi('biz:bizDaibanIng:list')")
    @GetMapping("/list")
    public R<PageInfo> list(DaibanIng daibanIng, HttpServletRequest request, HttpServletResponse response)
    {
        if(SecurityUtils.isAdmin(SecurityUtils.getUserId())){
                daibanIng.setCompanyId(null);
        }else{
                     daibanIng.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
                 }
        daibanIng.setPage(new PageDomain(request, response));
        return R.data(daibanIngService.findPage(daibanIng));
    }

    /**
     * 获取待办事项详细信息
     */
    @PreAuthorize("@ss.hasPermi('biz:bizDaibanIng:query')")
    @GetMapping(value = "/{id}")
    public R<DaibanIng> detail(@PathVariable("id") String id)
    {
        return R.data(daibanIngService.get(id));
    }

    /**
     * 新增待办事项
     */
    @PreAuthorize("@ss.hasPermi('biz:bizDaibanIng:add')")
    @Log(title = "待办事项", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody @Validated  DaibanIng daibanIng)
    {
        return R.status(daibanIngService.save(daibanIng));
    }

    /**
     * 修改待办事项
     */
    @PreAuthorize("@ss.hasPermi('biz:bizDaibanIng:edit')")
    @Log(title = "待办事项", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody @Validated DaibanIng daibanIng)
    {
        return R.status(daibanIngService.save(daibanIng));
    }


    /**
     * 删除待办事项
     */
    @PreAuthorize("@ss.hasPermi('biz:bizDaibanIng:remove')")
    @Log(title = "待办事项", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids)
    {
        return R.status(daibanIngService.deleteDaibanIngByIds(ids));
    }

    /**
     * 获取最大编号
     */
    @PreAuthorize("@ss.hasPermi('biz:bizDaibanIng:query')")
    @GetMapping("/findMaxSort")
    public R findMaxSort()
    {
        return R.data(daibanIngService.findMaxSort(new DaibanIng()));
    }

    /**
     * 导出待办事项列表
     */
    @PreAuthorize("@ss.hasPermi('biz:bizDaibanIng:export')")
    @Log(title = "待办事项", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public R export(DaibanIng daibanIng)
    {

            if(SecurityUtils.isAdmin(SecurityUtils.getUserId())){
                    daibanIng.setCompanyId(null);
            }else{
                         daibanIng.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
                     }
        List<DaibanIng> list = daibanIngService.findList(daibanIng);
        ExcelUtil<DaibanIng> util = new ExcelUtil<DaibanIng>(DaibanIng.class);
        return util.exportExcel(list, "待办事项数据");
    }

}
